package cn.jingyuan.swan.system.web.controller.sys;

import cn.jingyuan.bee.utils.bean.BeanUtils;
import cn.jingyuan.swan.cloud.core.Result;
import cn.jingyuan.swan.cloud.core.ResultUtils;
import cn.jingyuan.swan.system.domain.sys.entity.App;
import cn.jingyuan.swan.system.model.ClientDetails;
import cn.jingyuan.swan.system.model.dto.SysAppDto;
import cn.jingyuan.swan.system.service.AppService;
import cn.jingyuan.swan.system.web.restful.AppRestful;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "App 接口")
@Slf4j
@RestController
public class AppController implements AppRestful {

    @Resource
    AppService appService;

    @ApiOperation(value = "获取应用基础信息", notes = "获取应用基础信息")
    @Override
    public Result<SysAppDto> getApp(String appId) {
        App appInfo = appService.getAppInfo(appId);

        Result<SysAppDto> result = ResultUtils.ok();
        if (null != appInfo) {
            SysAppDto appDto = new SysAppDto();
            BeanUtils.copyProperties(appInfo, appDto);

            result.setData(appDto);
        }

        return result;
    }

    @ApiOperation(value = "获取应用开发配置信息", notes = "获取应用开发配置信息")
    @Override
    public Result<ClientDetails> getAppClientInfo(String clientId) {
        ClientDetails clientDetails = appService.getSysClientDetails(clientId);

        return ResultUtils.ok(clientDetails);
    }

}
